﻿/**  版本信息模板在安装目录下，可自行修改。
* Employee.cs
*
* 功 能： N/A
* 类 名： Employee
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2013-4-20 08:41:50   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;

namespace DMZS.DAL
{
    /// <summary>
    /// 数据访问类:Employee
    /// </summary>
    public partial class Employee
    {
        public Employee()
        {
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(long ID)
        {
            var strSql = new StringBuilder();
            strSql.Append("select count(1) from Employee");
            strSql.Append(" where ID=@ID");
            var parameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.BigInt)
            };
            parameters[0].Value = ID;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public long Add(DMZS.Model.Employee model)
        {
            var strSql = new StringBuilder();
            strSql.Append("insert into Employee(");
            strSql.Append("Code,Name,FullName,Address,Birthday,Email,Telephone,IsStop,DepartmentID,NamePY,Remark)");
            strSql.Append(" values (");
            strSql.Append("@Code,@Name,@FullName,@Address,@Birthday,@Email,@Telephone,@IsStop,@DepartmentID,@NamePY,@Remark)");
            strSql.Append(";select @@IDENTITY");
            var parameters = new SqlParameter[] { new SqlParameter("@Code", SqlDbType.NVarChar, 50),
                    new SqlParameter("@Name", SqlDbType.NVarChar, 100),
                    new SqlParameter("@FullName", SqlDbType.NVarChar, 200),
                    new SqlParameter("@Address", SqlDbType.NVarChar, 100),
                    new SqlParameter("@Birthday", SqlDbType.DateTime),
                    new SqlParameter("@Email", SqlDbType.NVarChar, 100),
                    new SqlParameter("@Telephone", SqlDbType.NVarChar, 200),
                    new SqlParameter("@IsStop", SqlDbType.Int, 4),
                    new SqlParameter("@DepartmentID", SqlDbType.Int, 4),
                    new SqlParameter("@NamePY", SqlDbType.NChar, 10),
                    new SqlParameter("@Remark", SqlDbType.NVarChar, 500) };
            parameters[0].Value = model.Code;
            parameters[1].Value = model.Name;
            parameters[2].Value = model.FullName;
            parameters[3].Value = model.Address;
            parameters[4].Value = model.Birthday;
            parameters[5].Value = model.Email;
            parameters[6].Value = model.Telephone;
            parameters[7].Value = model.IsStop;
            parameters[8].Value = model.DepartmentID;
            parameters[9].Value = model.NamePY;
            parameters[10].Value = model.Remark;

            var obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt64(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(DMZS.Model.Employee model)
        {
            var strSql = new StringBuilder();
            strSql.Append("update Employee set ");
            strSql.Append("Code=@Code,");
            strSql.Append("Name=@Name,");
            strSql.Append("FullName=@FullName,");
            strSql.Append("Address=@Address,");
            strSql.Append("Birthday=@Birthday,");
            strSql.Append("Email=@Email,");
            strSql.Append("Telephone=@Telephone,");
            strSql.Append("IsStop=@IsStop,");
            strSql.Append("DepartmentID=@DepartmentID,");
            strSql.Append("NamePY=@NamePY,");
            strSql.Append("Remark=@Remark");
            strSql.Append(" where ID=@ID");
            var parameters = new SqlParameter[] { new SqlParameter("@Code", SqlDbType.NVarChar, 50),
                    new SqlParameter("@Name", SqlDbType.NVarChar, 100),
                    new SqlParameter("@FullName", SqlDbType.NVarChar, 200),
                    new SqlParameter("@Address", SqlDbType.NVarChar, 100),
                    new SqlParameter("@Birthday", SqlDbType.DateTime),
                    new SqlParameter("@Email", SqlDbType.NVarChar, 100),
                    new SqlParameter("@Telephone", SqlDbType.NVarChar, 200),
                    new SqlParameter("@IsStop", SqlDbType.Int, 4),
                    new SqlParameter("@DepartmentID", SqlDbType.Int, 4),
                    new SqlParameter("@NamePY", SqlDbType.NChar, 10),
                    new SqlParameter("@Remark", SqlDbType.NVarChar, 500),
                    new SqlParameter("@ID", SqlDbType.BigInt, 8) };
            parameters[0].Value = model.Code;
            parameters[1].Value = model.Name;
            parameters[2].Value = model.FullName;
            parameters[3].Value = model.Address;
            parameters[4].Value = model.Birthday;
            parameters[5].Value = model.Email;
            parameters[6].Value = model.Telephone;
            parameters[7].Value = model.IsStop;
            parameters[8].Value = model.DepartmentID;
            parameters[9].Value = model.NamePY;
            parameters[10].Value = model.Remark;
            parameters[11].Value = model.ID;

            var rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(long ID)
        {
            var strSql = new StringBuilder();
            strSql.Append("delete from Employee ");
            strSql.Append(" where ID=@ID");
            var parameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.BigInt)
            };
            parameters[0].Value = ID;

            var rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string IDlist)
        {
            var strSql = new StringBuilder();
            strSql.Append("delete from Employee ");
            strSql.Append(" where ID in (" + IDlist + ")  ");
            var rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public DMZS.Model.Employee GetModel(long ID)
        {
            var strSql = new StringBuilder();
            strSql.Append("select  top 1 ID,Code,Name,FullName,Address,Birthday,Email,Telephone,IsStop,DepartmentID,NamePY,Remark from Employee ");
            strSql.Append(" where ID=@ID");
            var parameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.BigInt)
            };
            parameters[0].Value = ID;
            var ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public DMZS.Model.Employee DataRowToModel(DataRow row)
        {
            var model = new DMZS.Model.Employee();
            if (row != null)
            {
                if (row["ID"] != null && row["ID"].ToString() != string.Empty)
                {
                    model.ID = long.Parse(row["ID"].ToString());
                }
                if (row["Code"] != null)
                {
                    model.Code = row["Code"].ToString();
                }
                if (row["Name"] != null)
                {
                    model.Name = row["Name"].ToString();
                }
                if (row["FullName"] != null)
                {
                    model.FullName = row["FullName"].ToString();
                }
                if (row["Address"] != null)
                {
                    model.Address = row["Address"].ToString();
                }
                if (row["Birthday"] != null && row["Birthday"].ToString() != string.Empty)
                {
                    model.Birthday = DateTime.Parse(row["Birthday"].ToString());
                }
                if (row["Email"] != null)
                {
                    model.Email = row["Email"].ToString();
                }
                if (row["Telephone"] != null)
                {
                    model.Telephone = row["Telephone"].ToString();
                }
                if (row["IsStop"] != null && row["IsStop"].ToString() != string.Empty)
                {
                    model.IsStop = int.Parse(row["IsStop"].ToString());
                }
                if (row["DepartmentID"] != null && row["DepartmentID"].ToString() != string.Empty)
                {
                    model.DepartmentID = int.Parse(row["DepartmentID"].ToString());
                }
                if (row["NamePY"] != null)
                {
                    model.NamePY = row["NamePY"].ToString();
                }
                if (row["Remark"] != null)
                {
                    model.Remark = row["Remark"].ToString();
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            var strSql = new StringBuilder();
            strSql.Append("select ID,Code,Name,FullName,Address,Birthday,Email,Telephone,IsStop,DepartmentID,NamePY,Remark ");
            strSql.Append(" FROM Employee ");
            if (strWhere.Trim() != string.Empty)
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            var strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" ID,Code,Name,FullName,Address,Birthday,Email,Telephone,IsStop,DepartmentID,NamePY,Remark ");
            strSql.Append(" FROM Employee ");
            if (strWhere.Trim() != string.Empty)
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            var strSql = new StringBuilder();
            strSql.Append("select count(1) FROM Employee ");
            if (strWhere.Trim() != string.Empty)
            {
                strSql.Append(" where " + strWhere);
            }
            var obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            var strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.ID desc");
            }
            strSql.Append(")AS Row, T.*  from Employee T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }


        /// <summary>
        /// 获得数据列表 扩展 待完善
        /// </summary>
        /// <param name="DepartmentTypeID">部门类型ID</param>
        /// <param name="DepartmentID">部门ID,DepartmentTypeID=0时有效</param>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public DataSet GetListForUIExpand(int DepartmentTypeID, int DepartmentID, string strWhere)
        {
            var strSql = @"
if @DeptID>0
begin
	select e.ID,e.Code,e.Name,e.FullName,e.Address,e.Birthday,e.Email,e.Telephone,e.IsStop,e.DepartmentID,e.NamePY,e.Remark, 
		d.Code DepartmentCode, d.Name DepartmentName
	from dbo.Employee e
	left join dbo.DepartmentNew d on d.ID=e.DepartmentID
	where e.DepartmentID=@DeptID
	return
end

if @DeptTypeID>0
begin
	select e.ID,e.Code,e.Name,e.FullName,e.Address,e.Birthday,e.Email,e.Telephone,e.IsStop,e.DepartmentID,e.NamePY,e.Remark, 
		d.Code DepartmentCode, d.Name DepartmentName
	from dbo.Employee e
	left join dbo.DepartmentNew d on d.ID=e.DepartmentID
	where e.DepartmentID in (select ID from DepartmentNew where TypeID=@DeptTypeID)
end";
            strSql = string.Format(strSql, strWhere.Trim().Length == 0 ? "1=1" : strWhere);
            var parameters = new SqlParameter[] { new SqlParameter("@DeptID", SqlDbType.Int, 4),
                    new SqlParameter("@DeptTypeID", SqlDbType.Int, 4)
            };
            parameters[0].Value = DepartmentTypeID;
            parameters[1].Value = DepartmentID;

            return DbHelperSQL.Query(strSql, parameters);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="DepartmentID"></param>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public DataSet GetListForUIExpand(int DepartmentID, string strWhere)
        {
            var strSql = @"
if @DepartmentID<>0
begin
	select e.ID,e.Code,e.Name,e.FullName,e.Address,e.Birthday,e.Email,e.Telephone,e.IsStop,e.DepartmentID,e.NamePY,e.Remark, 
		d.Code DepartmentCode, d.Name DepartmentName
	from dbo.Employee e
	left join dbo.DepartmentNew d on d.ID=e.DepartmentID
	where e.DepartmentID=@DepartmentID
	return
end else begin
    select e.ID,e.Code,e.Name,e.FullName,e.Address,e.Birthday,e.Email,e.Telephone,e.IsStop,e.DepartmentID,e.NamePY,e.Remark, 
		d.Code DepartmentCode, d.Name DepartmentName
	from dbo.Employee e
	left join dbo.DepartmentNew d on d.ID=e.DepartmentID
end";
            strSql = string.Format(strSql, strWhere.Trim().Length == 0 ? "1=1" : strWhere);
            var parameters = new SqlParameter[] { new SqlParameter("@DepartmentID", SqlDbType.Int, 4)
            };
            parameters[0].Value = DepartmentID;

            return DbHelperSQL.Query(strSql, parameters);
        }
        /// <summary>
        /// 获取数据行
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public DataRow GetRecordByID(long ID)
        {
            var strSql = @"
select e.ID,e.Code,e.Name,e.FullName,e.Address,e.Birthday,e.Email,e.Telephone,e.IsStop,e.DepartmentID,e.NamePY,e.Remark, 
		d.Code DepartmentCode, d.Name DepartmentName
	from dbo.Employee e
	left join dbo.DepartmentNew d on d.ID=e.DepartmentID
	where e.ID=" + ID.ToString();

            var ds = DbHelperSQL.Query(strSql);
            if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
            {
                return null;
            }
            else
            {
                return ds.Tables[0].Rows[0];
            }
        }
        /// <summary>
        /// 更新记录
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public long UpdateExpand(DMZS.Model.Employee model)
        {
            var strSql = @"
declare @typeCount int, @codeCount int
select @codeCount=count(1) from Employee where Code=@Code and ID<>@ID
if @codeCount>0 begin
    select -1000    --编号重复
    return
end

select @typeCount=count(1) from DepartmentNew where ID=@DepartmentID
if @typeCount=0 begin
    select -1001    --部门不存在
    return
end

update Employee set 
    Code=@Code,
    Name=@Name,
    FullName=@FullName,
    Address=@Address,
    Birthday=@Birthday,
    Email=@Email,
    Telephone=@Telephone,
    IsStop=@IsStop,
    DepartmentID=@DepartmentID,
    NamePY=@NamePY,
    Remark=@Remark
where ID=@ID
select @ID
";
            var parameters = new SqlParameter[] { new SqlParameter("@Code", SqlDbType.NVarChar, 50),
                    new SqlParameter("@Name", SqlDbType.NVarChar, 100),
                    new SqlParameter("@FullName", SqlDbType.NVarChar, 200),
                    new SqlParameter("@Address", SqlDbType.NVarChar, 100),
                    new SqlParameter("@Birthday", SqlDbType.DateTime),
                    new SqlParameter("@Email", SqlDbType.NVarChar, 100),
                    new SqlParameter("@Telephone", SqlDbType.NVarChar, 200),
                    new SqlParameter("@IsStop", SqlDbType.Int, 4),
                    new SqlParameter("@DepartmentID", SqlDbType.Int, 4),
                    new SqlParameter("@NamePY", SqlDbType.NChar, 10),
                    new SqlParameter("@Remark", SqlDbType.NVarChar, 500),
                    new SqlParameter("@ID", SqlDbType.BigInt, 8) };
            parameters[0].Value = model.Code;
            parameters[1].Value = model.Name;
            parameters[2].Value = model.FullName;
            parameters[3].Value = model.Address;
            parameters[4].Value = model.Birthday;
            parameters[5].Value = model.Email;
            parameters[6].Value = model.Telephone;
            parameters[7].Value = model.IsStop;
            parameters[8].Value = model.DepartmentID;
            parameters[9].Value = model.NamePY;
            parameters[10].Value = model.Remark;
            parameters[11].Value = model.ID;

            var result = DbHelperSQL.GetSingle(strSql, parameters);
            if (result != null)
            {
                return Convert.ToInt64(result);
            }
            else
            {
                return 0;
            }
        }
        /// <summary>
        /// 添加记录
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public long AddExpand(DMZS.Model.Employee model)
        {
            var strSql = @"
declare @typeCount int, @codeCount int
select @codeCount=count(1) from Employee where Code=@Code
if @codeCount>0 begin
    select -1000    --编号重复
    return
end

select @typeCount=count(1) from DepartmentNew where ID=@DepartmentID
if @typeCount=0 begin
    select -1001    --部门不存在
    return
end

insert into Employee(Code,Name,FullName,Address,Birthday,Email,Telephone,IsStop,DepartmentID,NamePY,Remark)
values (@Code,@Name,@FullName,@Address,@Birthday,@Email,@Telephone,@IsStop,@DepartmentID,@NamePY,@Remark)
select @@IDENTITY";

            var parameters = new SqlParameter[] { new SqlParameter("@Code", SqlDbType.NVarChar, 50),
                    new SqlParameter("@Name", SqlDbType.NVarChar, 100),
                    new SqlParameter("@FullName", SqlDbType.NVarChar, 200),
                    new SqlParameter("@Address", SqlDbType.NVarChar, 100),
                    new SqlParameter("@Birthday", SqlDbType.DateTime),
                    new SqlParameter("@Email", SqlDbType.NVarChar, 100),
                    new SqlParameter("@Telephone", SqlDbType.NVarChar, 200),
                    new SqlParameter("@IsStop", SqlDbType.Int, 4),
                    new SqlParameter("@DepartmentID", SqlDbType.Int, 4),
                    new SqlParameter("@NamePY", SqlDbType.NChar, 10),
                    new SqlParameter("@Remark", SqlDbType.NVarChar, 500) };
            parameters[0].Value = model.Code;
            parameters[1].Value = model.Name;
            parameters[2].Value = model.FullName;
            parameters[3].Value = model.Address;
            parameters[4].Value = model.Birthday;
            parameters[5].Value = model.Email;
            parameters[6].Value = model.Telephone;
            parameters[7].Value = model.IsStop;
            parameters[8].Value = model.DepartmentID;
            parameters[9].Value = model.NamePY;
            parameters[10].Value = model.Remark;

            var obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt64(obj);
            }
        }


        /// <summary>
        /// 第一条记录
        /// </summary>
        /// <returns></returns>
        public DataRow GetFirst()
        {
            var strSql = @"
	select top 1 e.ID,e.Code,e.Name,e.FullName,e.Address,e.Birthday,e.Email,e.Telephone,e.IsStop,e.DepartmentID,e.NamePY,e.Remark, 
		d.Code DepartmentCode, d.Name DepartmentName
	from dbo.Employee e
	left join dbo.DepartmentNew d on d.ID=e.DepartmentID";

            var ds = DbHelperSQL.Query(strSql);
            if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
            {
                return null;
            }
            else
            {
                return ds.Tables[0].Rows[0];
            }
        }

        /// <summary>
        /// 最后一条记录
        /// </summary>
        /// <returns></returns>
        public DataRow GetLast()
        {
            var strSql = @"
	select top 1 e.ID,e.Code,e.Name,e.FullName,e.Address,e.Birthday,e.Email,e.Telephone,e.IsStop,e.DepartmentID,e.NamePY,e.Remark, 
		d.Code DepartmentCode, d.Name DepartmentName
	from dbo.Employee e
	left join dbo.DepartmentNew d on d.ID=e.DepartmentID
    order by e.ID desc";

            var ds = DbHelperSQL.Query(strSql.ToString());
            if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
            {
                return null;
            }
            return ds.Tables[0].Rows[0];
        }

        /// <summary>
        /// 上一条记录
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public DataRow GetPrevious(long ID)
        {
            var strSql = @"
    select top 1 e.ID,e.Code,e.Name,e.FullName,e.Address,e.Birthday,e.Email,e.Telephone,e.IsStop,e.DepartmentID,e.NamePY,e.Remark, 
		d.Code DepartmentCode, d.Name DepartmentName
	from dbo.Employee e
	left join dbo.DepartmentNew d on d.ID=e.DepartmentID
    where e.ID<@ID
    order by e.ID desc";

            var parameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.BigInt)
            };
            parameters[0].Value = ID;

            var ds = DbHelperSQL.Query(strSql, parameters);
            if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
            {
                return null;
            }
            return ds.Tables[0].Rows[0];
        }

        /// <summary>
        /// 下一条记录
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public DataRow GetNext(long ID)
        {
            var strSql = @"
	select top 1 e.ID,e.Code,e.Name,e.FullName,e.Address,e.Birthday,e.Email,e.Telephone,e.IsStop,e.DepartmentID,e.NamePY,e.Remark, 
		d.Code DepartmentCode, d.Name DepartmentName
	from dbo.Employee e
	left join dbo.DepartmentNew d on d.ID=e.DepartmentID
    where e.ID>@ID
    order by e.ID";
            var parameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.BigInt)
            };
            parameters[0].Value = ID;

            var ds = DbHelperSQL.Query(strSql, parameters);
            if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
            {
                return null;
            }
            return ds.Tables[0].Rows[0];
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        /// <param name="Code">编号</param>
        /// <returns></returns>
        public DMZS.Model.Employee GetModel(string Code)
        {
            var strSql = new StringBuilder();
            strSql.Append("select  top 1 ID,Code,Name,FullName,Address,Birthday,Email,Telephone,IsStop,DepartmentID,NamePY,Remark from Employee ");
            strSql.Append(" where Code=@Code");
            var parameters = new SqlParameter[] { new SqlParameter("@Code", SqlDbType.NVarChar,50)
            };
            parameters[0].Value = Code;
            var ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获取员工列表 对话框
        /// </summary>
        /// <param name="DepartmentCode"></param>
        /// <param name="DepartmentName"></param>
        /// <param name="EmployeeCode"></param>
        /// <param name="EmployeeName"></param>
        /// <returns></returns>
        public DataSet GetListForDialog(string DepartmentCode, string DepartmentName, string EmployeeCode, string EmployeeName)
        {
            var strSql = @"
select e.ID,e.Code,e.Name,e.FullName,e.Address,e.Birthday,e.Email,e.Telephone,e.IsStop,e.DepartmentID,e.NamePY,e.Remark, 
	d.Code DepartmentCode, d.Name DepartmentName
from dbo.Employee e
left join dbo.DepartmentNew d on d.ID=e.DepartmentID
where e.Code like '%'+@EmployeeCode+'%' and e.Name like '%'+@EmployeeName+'%' 
and  d.Code like '%'+@DepartmentCode+'%' and d.Name like '%'+@DepartmentName+'%' 
";

            var parameters = new SqlParameter[] { 
                new SqlParameter("@EmployeeCode", SqlDbType.NVarChar, 50),
                new SqlParameter("@EmployeeName", SqlDbType.NVarChar, 100),
                new SqlParameter("@DepartmentCode", SqlDbType.NVarChar, 50),
                new SqlParameter("@DepartmentName", SqlDbType.NVarChar, 100),
            };
            parameters[0].Value = EmployeeCode ;
            parameters[1].Value = EmployeeName ;
            parameters[2].Value = DepartmentCode;
            parameters[3].Value = DepartmentName;

            return DbHelperSQL.Query(strSql, parameters);
        }
    }
}

